//
//  SKErJiVc.m
//  Hand-held_kitchen
//
//  Created by 张张烨 on 16/1/17.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SKErJiVc.h"
#import <AFNetworking.h>
#import <UIImageView+WebCache.h>
#import "SKErJiCell.h"
#import "SkErJiModle.h"
#import "SKErJiPingLunCell.h"
@interface SKErJiVc ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)UITableView *tableview;/**<  table */
@property(nonatomic,retain)NSMutableArray *shangArr;/**<  上办部分的数组 */
@property(nonatomic,retain)NSMutableArray *xiaArr;/**<  下半部分的数组 */
@property(nonatomic,retain)NSDictionary *dic;/**<  下半部分字典 */

@end

@implementation SKErJiVc
- (void)dealloc
{
    [_tableview release];
    [_shangArr release];
    [_xiaArr release];
    [_dic release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = self.title;
    /**<  数据 */
    [self data];
    /**<  table */
    [self tableView1];
    // UIWebView 加载网页数据 直接适配屏幕
    UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height - (420 * GAO))];
    wv.backgroundColor = [UIColor whiteColor];

    /**<  锁定web屏幕 */
    wv.scrollView.scrollEnabled = NO;

    _tableview.tableHeaderView = wv;
    // 加载网址
    NSString *url =[NSString stringWithFormat:@"http://h5.izhangchu.com/micro/shike.php?&material_id=%@",self.Iddddd];
    [wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
    [wv release];
    
   
}
/**<  解析数据 */
-(void)data{
    
    NSString *str = [NSString stringWithFormat:@"http://api.izhangchu.com/?relate_id=%@&methodName=CommentList&size=20&page=1&type=2&version=4.3&",self.Iddddd];
    
   
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:str parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       
        NSArray *arr = responseObject[@"data"][@"data"];
        
        self.xiaArr = [SkErJiModle modelHanderWithArray:arr];
        self.dic = responseObject[@"data"];
        
        
        [_tableview reloadData];
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}

/**<  创建table */
-(void)tableView1{
    self.tableview = [[UITableView alloc]initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    _tableview.dataSource = self;
    _tableview.delegate =self;
    [self.view addSubview:_tableview];
    [_tableview registerClass:[SKErJiCell class] forCellReuseIdentifier:@"cell"];
    [_tableview registerClass:[SKErJiPingLunCell class] forCellReuseIdentifier:@"cell1"];
    
    [_tableview release];
    
}
/**<  table个数 */
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    NSInteger a = [_dic[@"total"] integerValue];
    return _xiaArr.count;
}

/**<  cell */
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    /**<  cell等于0是哪个评论图片和评论条数 */
    if (indexPath.row == 0) {
        SKErJiPingLunCell *cell1 = [tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath];
//        SkErJiModle *m = _xiaArr[indexPath.row];
        cell1.pinglunshu.text = [NSString stringWithFormat:@"%@条评论",_dic[@"total"]];
        cell1.tupian.image = [UIImage imageNamed:@"pinglun"];
        return cell1;
    }else{
    /**<  评论数 */
  SKErJiCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    SkErJiModle *m = _xiaArr[indexPath.row];
    [cell.touxiang sd_setImageWithURL:[NSURL URLWithString:m.head_img]];
    cell.nicheng.text = m.nick;
    cell.neirong.text = m.content;
    cell.shijian.text = m.create_time;
    cell.xiaotupian.image = [UIImage imageNamed:@"dun"];
    
    return cell;
    }
}

/**<  table Cell的高度 */
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100 * GAO;
}

/**<  没用 */
- (void)webView:(UIWebView *)webView
{
    
    [self release];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
